package com.shenghua.utils.beans;

/**
 * Created by Administrator on 2018/8/28.
 * @param <T>
 * 用于返回客户端
 * 数据传输对象（后端输出对象）
 */
public class Dto<T> {
    private int status;
    private T data; //具体返回数据内容(pojo、自定义VO、其他)
    private int errorcode;//该错误码为自定义，一般0表示无错
    private String msg;//对应的提示信息
    private boolean success; //判断系统是否出错做出相应的true或者false的返回，与业务无关，出现的各种异常

    public Dto(){
        data = null;
        errorcode = 0;
        msg = null;
        success = true;
    }

    // 返回成功
    public void ReturnSuccess(T data,ErrorCode errorCode){
        setData(data);
        setMsg(errorCode.getValue());
        setStatus(errorCode.getKey());
        setErrorcode(0);
        setSuccess(true);
    }

    // 返回失败
    public void ReturnFail(T data,ErrorCode errorCode){
        setData(data);
        setMsg(errorCode.getValue());
        setStatus(errorCode.getKey());
        setErrorcode(errorCode.getKey());
        setSuccess(false);
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getErrorcode() {
        return errorcode;
    }

    public void setErrorcode(int errorcode) {
        this.errorcode = errorcode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}
